Skip to content

Update websocket.py - #77

Closed
MamaevPro wants to merge 1 commit into
MaxApiTeam:mainfrom
MamaevPro:patch-1
Closed

Update websocket.py#77
MamaevPro wants to merge 1 commit into
MaxApiTeam:mainfrom
MamaevPro:patch-1

Conversation

@MamaevPro

@MamaevPro MamaevPro commented Aug 4, 2026

Copy link
Copy Markdown

Fix SSL error:
Traceback (most recent call last):
File "pymax/base.py", line 131, in start
File "pymax/app.py", line 88, in start
ConnectionError: Failed to connect and handshake: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)

Summary by CodeRabbit

  • Chores
    • Updated WebSocket connection SSL configuration to improve compatibility across different certificate scenarios.

Fix SSL error:
Traceback (most recent call last):
 File "pymax/base.py", line 131, in start
 File "pymax/app.py", line 88, in start
ConnectionError: Failed to connect and handshake: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds a module-level SSL context in the WebSocket transport module that disables hostname verification and certificate validation. Both the proxied and direct WebSocket connection code paths now pass this context to the connect call.

Changes

SSL Context for WebSocket Connections

Layer / File(s) Summary
Add and apply unverified SSL context
src/pymax/transport/websocket.py
A module-level ssl_context variable is created with hostname checking and certificate verification disabled. Both the proxied and direct connection paths pass this context to client.connect.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ink-developer

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description states the SSL error but omits the required change type, related issue, testing details, and clear PR summary. Add the required sections for description, change type, related issue, and testing, including an example that verifies the SSL fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the changed file but does not state that the PR fixes a WebSocket SSL certificate verification error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pymax/transport/websocket.py`:
- Around line 7-10: Remove the assignments disabling validation from the
module-level ssl_context in websocket.py, preserving the verified defaults
created by ssl.create_default_context(). If private CA support is required, load
it via load_verify_locations() without changing check_hostname or verify_mode;
any insecure local-development mode must be explicit and opt-in rather than
shared by both connection paths.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d81a68d5-d8be-4de0-9863-e1a4a20cce73

📥 Commits

Reviewing files that changed from the base of the PR and between 8c40b71 and 0bc20c2.

📒 Files selected for processing (1)
  • src/pymax/transport/websocket.py

Comment on lines +7 to +10
import ssl
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Tracked websocket.py files:\n'
git ls-files | grep -E '(^|/)websocket\.py$' || true

printf '\nRelevant file excerpt:\n'
if [ -f src/pymax/transport/websocket.py ]; then
  nl -ba src/pymax/transport/websocket.py | sed -n '1,80p'
fi

printf '\nSearch for ssl_context use and transport connect definitions:\n'
rg -n "ssl_context|check_hostname|verify_mode|def connect|client\.connect|async def connect" src/pymax/transport/websocket.py src/pymax/transport || true

printf '\nPython ssl semantics probe for create_default_context mutations:\n'
python3 - <<'PY'
import ssl
ctx = ssl.create_default_context()
before = (ctx.check_hostname, ctx.verify_mode == ssl.CERT_NONE)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
after = (ctx.check_hostname, ctx.verify_mode == ssl.CERT_NONE)
print("before_hostname_true:", before[0])
print("before_cert_verified:", not before[1])
print("after_hostname_false:", after[0])
print("after_cert_none:", after[1])
PY

printf '\nPackage version constraint context:\n'
if [ -f pyproject.toml ]; then
  sed -n '1,80p' pyproject.toml | nl -ba
fi

Repository: MaxApiTeam/PyMax

Length of output: 279


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Relevant file excerpt:\n'
awk '{printf "%6d\t%s\n", NR, $0}' src/pymax/transport/websocket.py | sed -n '1,80p'

printf '\nSearch for ssl_context use and transport connect definitions:\n'
rg -n "ssl_context|check_hostname|verify_mode|def connect|client\.connect|async def connect" src/pymax/transport src/pymax || true

printf '\nPython ssl semantics probe for create_default_context mutations:\n'
python3 - <<'PY'
import ssl
ctx = ssl.create_default_context()
before = (ctx.check_hostname, ctx.verify_mode == ssl.CERT_NONE)
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
after = (ctx.check_hostname, ctx.verify_mode == ssl.CERT_NONE)
print("before_hostname_true:", before[0])
print("before_cert_verified:", not before[1])
print("after_hostname_false:", after[0])
print("after_cert_none:", after[1])
PY

printf '\nPackage version constraint context:\n'
awk '{printf "%6d\t%s\n", NR, $0}' pyproject.toml | sed -n '1,80p'

printf '\nCall sites for build_connection / WebSocketTransport:\n'
rg -n "WebSocketTransport|_build_connection|WebSocketTransport\(" src/py* tests || true

Repository: MaxApiTeam/PyMax

Length of output: 8191


Security Misconfiguration (CWE-295): Improper Certificate Validation

Reachability: External

Do not ship an unverified WebSocket context.

Lines 8-10 set verify_mode to ssl.CERT_NONE and disable check_hostname, then both connection paths use the same context. This removes server certificate and hostname validation, so an attacker who can intercept the connection or control the proxy can impersonate the endpoint and read or modify WebSocket traffic.

Keep the default verified context. For private CAs, fix the server chain or load the CA bundle with load_verify_locations() while retaining hostname checking. Make any insecure local-dev mode explicit and opt-in.

Proposed fix
 ssl_context = ssl.create_default_context()
-ssl_context.check_hostname = False
-ssl_context.verify_mode = ssl.CERT_NONE
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import ssl
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
import ssl
ssl_context = ssl.create_default_context()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pymax/transport/websocket.py` around lines 7 - 10, Remove the assignments
disabling validation from the module-level ssl_context in websocket.py,
preserving the verified defaults created by ssl.create_default_context(). If
private CA support is required, load it via load_verify_locations() without
changing check_hostname or verify_mode; any insecure local-development mode must
be explicit and opt-in rather than shared by both connection paths.

@ink-developer

ink-developer commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Дело в том что макс изменил вебсокет путь и протокол в вебе, в ветке dev/2.4.0 всё исправлено (обновление уже скоро)
Если нужно решение прям сейчас - client.extra_config.url = "wss://api.oneme.ru/websocket" (Но там бинарный протокол, тот который сейчас в main скорее всего не сработает)
Так же можно установить версию с ветки

uv add git+https://github.com/MaxApiTeam/PyMax@dev/2.4.0
# или 
pip install git+https://github.com/MaxApiTeam/PyMax@dev/2.4.0

@MamaevPro

Copy link
Copy Markdown
Author

У ветки dev 2.4.0
Traceback (most recent call last):
File "MaxLiker.py", line 4, in
File "pymax/client_web.py", line 63, in init
File "pymax/base.py", line 112, in _init_runtime
File "pymax/base.py", line 115, in _build_app
File "pymax/app.py", line 43, in init
File "pymax/fingerprint/fingerprint.py", line 14, in init
File "importlib/resources/_common.py", line 22, in files
File "importlib/resources/_common.py", line 53, in get_package
File "importlib/resources/_common.py", line 44, in resolve
File "importlib/init.py", line 126, in import_module
File "", line 1206, in _gcd_import
File "", line 1178, in _find_and_load
File "", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pymax._data'
[PYI-3458:ERROR] Failed to execute script 'MaxLiker' due to unhandled exception!

@MamaevPro
MamaevPro deleted the patch-1 branch August 4, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants